package com.lanhao.aot.semaphore;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class SemaphoreTest {
	private static Semaphore s = new Semaphore(3);
	private static ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 30, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>(200));
	public static void main(String[] args) {
		for (;;) {
			executor.execute(() -> {
				try {
					s.acquire(1);
					System.out.println("执行exec方法" + System.currentTimeMillis());
		            Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				} finally {
					s.release(1);
				}
			});
		}
	}
}
